# 编译器
CXX = g++

# 编译选项
CXXFLAGS = -g -std=c++11 -I include -I/usr/local/include  # 确保 tinyxml2.h 可以被找到

# 链接选项
LDFLAGS =

# 目标文件
TARGETS = 01_test 02_test 00_test 03_test 05_test 06_test 07_test

# 源文件路径
SRC_DIR = src

# 第三方库路径
LIB_DIR = /usr/local/lib

# 库文件
LIBS = -lpthread -lwfrest -lworkflow  # 添加 wfrest 和 workflow 库

# 所有目标
all: $(TARGETS)

# 清理生成的文件
clean:
	rm -f $(TARGETS) *.o

# 01_test
01_test: testpage.o Configuration.o PageLib.o DirScanner.o tinyxml2.o
	$(CXX) $^ -o $@ $(LDFLAGS) $(LIBS)

testpage.o: testpage.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

Configuration.o: $(SRC_DIR)/Configuration.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

PageLib.o: $(SRC_DIR)/PageLib.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

DirScanner.o: $(SRC_DIR)/DirScanner.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

tinyxml2.o: $(SRC_DIR)/tinyxml2.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

# 02_test
02_test: testlib.o PagelibPreprocessor.o SplitToolJieba.o Configuration.o tinyxml2.o
	$(CXX) $^ -o $@ $(LDFLAGS) $(LIBS)

testlib.o: testlib.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

PagelibPreprocessor.o: $(SRC_DIR)/PagelibPreprocessor.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

SplitToolJieba.o: $(SRC_DIR)/SplitToolJieba.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

# 00_test
00_test: testdir.o SplitToolJieba.o Configuration.o DictProducer.o tinyxml2.o
	$(CXX) $^ -o $@ $(LDFLAGS) $(LIBS)

testdir.o: testdir.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

DictProducer.o: $(SRC_DIR)/DictProducer.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

# 03_test
03_test: testjson.o Dictionary.o tinyxml2.o
	$(CXX) $^ -o $@ $(LDFLAGS) $(LIBS)

testjson.o: testjson.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

Dictionary.o: $(SRC_DIR)/Dictionary.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

# 05_test
05_test: testrecommond.o KeyRecommander.o Candidate.o Dictionary.o tinyxml2.o
	$(CXX) $^ -o $@ $(LDFLAGS) $(LIBS)

testrecommond.o: testrecommond.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

KeyRecommander.o: $(SRC_DIR)/KeyRecommander.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

Candidate.o: $(SRC_DIR)/Candidate.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

# 06_test
06_test: testin.o Webpage.o WebPageQuery.o SplitToolJieba.o Configuration.o tinyxml2.o
	$(CXX) $^ -o $@ $(LDFLAGS) $(LIBS)

testin.o: testin.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

Webpage.o: $(SRC_DIR)/Webpage.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

WebPageQuery.o: $(SRC_DIR)/WebPageQuery.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

# 07_test
07_test: testnet.o WfRestSer.o Configuration.o WebPageQuery.o SplitToolJieba.o Webpage.o Candidate.o tinyxml2.o KeyRecommander.o Dictionary.o
	$(CXX) $^ -o $@ $(LDFLAGS) $(LIBS)

testnet.o: testnet.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

WfRestSer.o: $(SRC_DIR)/WfRestSer.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

# 依赖关系
testpage.o: testpage.cc
testlib.o: testlib.cc
testdir.o: testdir.cc
testjson.o: testjson.cc
testrecommond.o: testrecommond.cc
testin.o: testin.cc
testnet.o: testnet.cc

Configuration.o: $(SRC_DIR)/Configuration.cc
PageLib.o: $(SRC_DIR)/PageLib.cc
DirScanner.o: $(SRC_DIR)/DirScanner.cc
PagelibPreprocessor.o: $(SRC_DIR)/PagelibPreprocessor.cc
SplitToolJieba.o: $(SRC_DIR)/SplitToolJieba.cc
DictProducer.o: $(SRC_DIR)/DictProducer.cc
Dictionary.o: $(SRC_DIR)/Dictionary.cc
KeyRecommander.o: $(SRC_DIR)/KeyRecommander.cc
Candidate.o: $(SRC_DIR)/Candidate.cc
Webpage.o: $(SRC_DIR)/Webpage.cc
WebPageQuery.o: $(SRC_DIR)/WebPageQuery.cc
tinyxml2.o: $(SRC_DIR)/tinyxml2.cc
WfRestSer.o: $(SRC_DIR)/WfRestSer.cc

.PHONY: all clean
